//
//  RSWDataOperation+BasicData.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 16/11/30.
//  Copyright © 2016年 com.xtion.crm. All rights reserved.
//

#import "RSWDataOperation+BasicData.h"
#import "RSWDBOperation+BasicData.h"

@implementation RSWDataOperation (BasicData)

-(void)getMenuListCompletion:(void(^)(NSInteger nResult, NSArray *output, NSError *error))completion
{
    EDOMRequestStateType stateType = [super requestAsyncBlock:^{
        [self progressViewBegin:@"加载菜单权限"];
        NSInteger thisResult = FALSE;
        NSArray *thisSummary = nil;
        NSError *thisError = nil;
        
        RSWDBOperation *db = [RSWDBOperation new];
        
        XLGResult *r = [db getMenuList];
        thisResult = r.outResult;
        thisSummary = r.outObj;
        thisError = r.outError;
        
        [super requestResult:thisResult output:nil error:thisError completion:^(NSInteger nResult, id output, NSError *error)
         {
             completion(thisResult, thisSummary, thisError);
         }];
        
        [self progressViewEnd];
    }];
    if(stateType == EDOMRequestStateTypeCanNotRequest)
        completion(TERMINATEREADWRITE,nil,nil);
}


-(void)getSubMenuListByParentCode:(NSString*)pCode Completion:(void(^)(NSInteger nResult, NSArray *output, NSError *error))completion
{
    EDOMRequestStateType stateType = [super requestAsyncBlock:^{
        [self progressViewBegin:@"加载子菜单权限"];
        NSInteger thisResult = FALSE;
        NSArray *thisSummary = nil;
        NSError *thisError = nil;
        
        RSWDBOperation *db = [RSWDBOperation new];
        
        XLGResult *r = [db getSubMenuListByParentCode:pCode];
        thisResult = r.outResult;
        thisSummary = r.outObj;
        thisError = r.outError;
        
        [super requestResult:thisResult output:nil error:thisError completion:^(NSInteger nResult, id output, NSError *error)
         {
             completion(thisResult, thisSummary, thisError);
         }];
        
        [self progressViewEnd];
    }];
    if(stateType == EDOMRequestStateTypeCanNotRequest)
        completion(TERMINATEREADWRITE,nil,nil);
}

-(void)getSubMenuDictionaryByParentCode:(NSString*)pCode Completion:(void(^)(NSInteger nResult, XMSQueueDictionary *output, NSError *error))completion
{
    EDOMRequestStateType stateType = [super requestAsyncBlock:^{
        [self progressViewBegin:@"加载子菜单权限"];
        NSInteger thisResult = FALSE;
        NSArray *thisSummary = nil;
        NSError *thisError = nil;
        XMSQueueDictionary *thisDic = [XMSQueueDictionary new];
        
        RSWDBOperation *db = [RSWDBOperation new];
        
        XLGResult *r = [db getSubMenuListByParentCode:pCode];
        thisResult = r.outResult;
        thisSummary = r.outObj;
        thisError = r.outError;
        
        for(MenuInfo *info in thisSummary)
        {
            XLGResult *rChild = [db getSubMenuListByParentCode:info.code];
            if((rChild.outResult == YES) && (rChild.outObj != nil))
            {
                [thisDic setValue:rChild.outObj forKey:info.name];
            }
        }
        
        [super requestResult:thisResult output:nil error:thisError completion:^(NSInteger nResult, id output, NSError *error)
         {
             completion(thisResult, thisDic, thisError);
         }];
        
        [self progressViewEnd];
    }];
    if(stateType == EDOMRequestStateTypeCanNotRequest)
        completion(TERMINATEREADWRITE,nil,nil);
}

-(void)getWorkflowListCompletion:(void(^)(NSInteger nResult, NSArray *output, NSError *error))completion
{
    EDOMRequestStateType stateType = [super requestAsyncBlock:^{
        [self progressViewBegin:@"加载流程数据"];
        NSInteger thisResult = FALSE;
        NSArray *thisSummary = nil;
        NSError *thisError = nil;
        
        RSWDBOperation *db = [RSWDBOperation new];
        
        XLGResult *r = [db getWorkflowList];
        thisResult = r.outResult;
        thisSummary = r.outObj;
        thisError = r.outError;
        
        [super requestResult:thisResult output:nil error:thisError completion:^(NSInteger nResult, id output, NSError *error)
         {
             completion(thisResult, thisSummary, thisError);
         }];
        
        [self progressViewEnd];
    }];
    if(stateType == EDOMRequestStateTypeCanNotRequest)
        completion(TERMINATEREADWRITE,nil,nil);
}

@end
